'use strict';
exports.main = async (event, context) => {
  const { species_id } = event;
  const db = uniCloud.database();
  
  try {
    const { data } = await db.collection('comments')
      .where({
        species_id: species_id
      })
      .orderBy('createTime', 'desc')  // 按时间倒序排列
      .get();
    
    return {
      code: 200,
      message: '获取成功',
      data: data
    }
  } catch (error) {
    return {
      code: 500,
      message: error.message || '获取评论失败'
    }
  }
}; 